package ru.evga.inse.server.gwt.admin.client.menu.dict.street;

import ru.evga.gwt.lib.common.client.view.AbstractEntityListView;
import ru.evga.inse.server.gwt.common.client.domain.dict.StreetDto;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.text.shared.AbstractRenderer;
import com.google.gwt.text.shared.Renderer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTMLPanel;


/**
 * The outermost UI of the application.
 */
public class StreetListView
    extends AbstractEntityListView<StreetDto>
{
    interface Binder
        extends UiBinder<HTMLPanel, StreetListView>
    {
    }
    private static final Binder BINDER = GWT.create(Binder.class);
    @UiField
    CellTable<StreetDto> table;
    @UiField
    Button newButton;

    public StreetListView()
    {
        init(BINDER.createAndBindUi(this), table);
        newButton.addClickHandler(new ClickHandler()
        {
            public void onClick(ClickEvent event)
            {
                getDelegate().onCreateClicked();
            }
        });
        table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
        table.addColumn(new TextColumn<StreetDto>()
        {
            public String getValue(StreetDto object)
            {
                return String.valueOf(object.getId());
            }
        }, "Id");
        table.addColumn(new TextColumn<StreetDto>()
        {
            Renderer<java.lang.String> renderer = new AbstractRenderer<java.lang.String>()
            {
                public String render(java.lang.String obj)
                {
                    return obj == null ? "" : String.valueOf(obj);
                }
            };

            @Override
            public String getValue(StreetDto object)
            {
                return renderer.render(object.getName());
            }
        }, "Name");
        table.addColumn(new TextColumn<StreetDto>()
        {
            Renderer<java.lang.String> renderer = new AbstractRenderer<java.lang.String>()
            {
                public String render(java.lang.String obj)
                {
                    return obj == null ? "" : String.valueOf(obj);
                }
            };

            @Override
            public String getValue(StreetDto object)
            {
                return renderer.render(object.getCity().getName());
            }
        }, "City");
        addEditColumn(table);
        addRemoveColumn(table);
    }
}
